package provider.base;

import java.util.List;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import libra.model.JsonResult;
import libra.model.Provider_Pay;
import libraServer.ProviderReqService;

@RestController
@RequestMapping("provider")
public class ProviderReqController {
	@Autowired
	ProviderReqService service;
	
	@Value( "#{'${server.servlet.context-path}'.concat('[port(${server.port})]')}" )
	String identity;
	
	@RequestMapping("save")
	public Object save( String serial, HttpServletRequest req ) throws Exception{
		Provider_Pay pay = new Provider_Pay( identity );
		if( serial != null ) {
			pay.setSerial(serial);
		}
		service.SavePay(pay);
		pay.setOperator(identity);
		return new JsonResult<Provider_Pay>(0, identity, pay);
	}
	
	@RequestMapping("queryOne")
	public Object QueryOne( Integer id, HttpServletRequest req ) throws Exception{
		Provider_Pay queryOne = service.QueryOne(id);
		if( queryOne != null ){
			queryOne.setOperator(identity);
		}
		return new JsonResult<Provider_Pay>(0, identity, queryOne);
	}
	
	@RequestMapping("queryList")
	public Object queryList( HttpServletRequest req ) throws Exception{
		List<Provider_Pay> list = service.QueryPayList();
		list.forEach( ( pay )->{ pay.setOperator( identity ); } );
		return new JsonResult<List<Provider_Pay>>(0, identity, list);
	}
}
